export class session {
  static set(key: string, value: any) {
    if (typeof value == "object") {
      sessionStorage.setItem(key, JSON.stringify(value));
    } else {
      sessionStorage.setItem(key, value);
    }
    if (value == undefined || value == null) {
      sessionStorage.removeItem(key);
    }
  }

  static get(key: string) {
    var d = sessionStorage.getItem(key) as string
    if(!d) return d
    if (typeof JSON.parse(d) !== 'object') {
      return undefined;
    }
    return JSON.parse(d);
  }

  static remove(key: string) {
    sessionStorage.removeItem(key)
  }

  static clear() {
    sessionStorage.clear()
  }

  static count() {
    return sessionStorage.lenght
  }

} 